<?php
/**
 * 资讯公共方法
 * publiccontroller.php
 * Create on 2015-04-08 10:40:21
 * Create by yuebin
 */
namespace haibao\cms\business\control;
use haibao\cms\model\filter\Article as ArticleFilter;
use haibao\cms\model\filter\ArticleTag as ArticleTagFilter;
use haibao\cms\model\filter\ArticleProImage as ArticleProImageFilter;
use haibao\cms\model\filter\ArticleProperty as ArticlePropertyFilter;
use haibao\cms\model\filter\CelebrityImage as CelebrityImageFilter;
use haibao\cms\model\filter\ImageLibrary as ImageLibraryFitler;
use haibao\cms\model\filter\imagecollective\ImageCollective as ImageCollFilter;
use haibao\cms\model\filter\imagecollective\ImageCollectiveTag as ImageCollTagFilter;
use haibao\cms\model\filter\imagecollective\ImageCollectivePro as ImageCollProFilter;
use haibao\cms\model\filter\imagecollective\ImageCollectiveProperty as ImageCollPropertyFilter;
use haibao\cms\model\filter\imagecollective\ImageCollectiveArticle as ImageCollArticleFilter;
use haibao\frame\data\query\Condition;
use haibao\cms\business\control\PublicController as PublicControllerBusiness;
use haibao\cms\data\control\PublicController as PublicControllerData;
use \haibao\frame\data\query\Pager;
use \haibao\cms\business\BusinessException;
use \haibao\cms\business\Tag as TagBusiness;
use \haibao\cms\model\filter\DataMigrationMap as DataMigrationMapFilter;
use \haibao\cms\model\filter\WapInfo as WapInfoFilter;
use haibao\cms\model\data\WapInfo;

class ArticleController extends \haibao\cms\business\Base{

	const HAI_BAO_WANG_TAG = 2709;
	const QUERY_TYPE_CHANNEL = 1;// 根据频道查询资讯
	const QUERY_TYPE_CLICK = 2;// 根据点击量查询资讯
	const QUERY_TYPE_BRAND_STAR = 3;// 根据点击量查询品牌/明星信息
	const QUERY_TYPE_IMAGE_COLLECTIVE_CLICK = 4;// 根据点击量查询图集信息
	const QUERY_TYPE_LIST_NEW = 5;// 查询最新的资讯/图集列表
	const QUERY_TYPE_ARTICLE_IN_TOP_TAG_ID = 6; // 查询资讯必须包含当前频道标签
	const QUERY_TYPE_WAP_INFO_LIST = 7; // WAP获取资讯列表
	
	const INFO_TYPE_ARTICLE = 1;//资讯类型 文章
	const INFO_TYPE_IMAGE = 2;//资讯类型 图集
	const INFO_TYPE_ARTICLE_PIC = 3;//资讯类型 文章读图模式
	
	const DATE_TYPE_WEEK = 1;// 1周
	const DATE_TYPE_MONTH = 2;// 1月
	const DATE_TYPE_HALFWEEK = 3;// 半月
	
	private static $_instance;
	private $offset = 0;
	private $limit = 5;
	private $level = 5;
	private $bigLevel = 0;
	private $tagIds;
	private $tagUrls;
	private $isReturnPrimary = true;
	private $isArticleTag = false; // 是否需要通过文章标签搜索
	private $isConditionTag = true; // 是否需要通过标签ID作为条件
	private $isPrimaryTag = false;//是否是主标签 跟isTag对应这样才能保证取出的文章与标签ID一一对应
	private $isParentTag = true;//是否需要根据父标签ID搜索 否则根据标签ID搜索
	private $isReturnTag = false; // 是否需要标签信息
	private $isProImage = false;//是否返回文章导读图
	private $proImageLevel = array();//导读图等级
	private $relType;// 1表示品牌 2表示明星
	private $source;//来源
	private $isDate = false;//是否根据时间段查询
	private $isPage = false;// 是否分页
	private $dateType;//时间段类型 1一周 2一个月
	private $isImageColl = true;//是否需要图集数据
	private $currentPage = 1;//当前第几页
	private $pager;//分页对象
	private $primaryTag = 0;//主标签
	private $isCalendarData = false; //供造型日历使用
	
	private $hasParentId = false;
	private $orderByNew = true;//按照最新排序 否则按照点击量
	
	private $articleIdArr = array();
	private $collIdArr = array();
	
	private $tagIdArr = array();
	private $collTagIdArr = array();
	
	private $articles = array();
	private $imageColls = array();
	
	private $articleProImages = array();
	private $collProImages = array();
	
	private $tagInfo = array();
	private $collTagInfo = array();
	
	public $articleData;
	private $imageCollData;

	private $articleTagArr = array();//文章关联标签数组
	private $collTagArr = array();//图集关联标签数组
	
	private $allArticleId = array();
	
	private $getArticleInTags = array();
	
	public static function initArticleControl(){
		if(!self::$_instance instanceof self){
			self::$_instance = new self;
			self::$_instance->articleData = new \haibao\cms\data\Article();
			self::$_instance->imageCollData = new \haibao\cms\data\imagecollective\ImageCollective();
		}
		self::$_instance->isImageColl = true;
		return self::$_instance;
	}
	
	/**
	 *资讯调出规则：范围是？频道下属的？级资讯和？级图集1
	 *@param : Int $queryType 
	 */
	public function getChannelArticleAndAtiasByChannel(){
		
		$this->getArticlesByChannel();
		if($this->getIsImageColl()){
			$this->getImageCollByChannel();
			list($first,$second) = $this->packageQueryTypeChannelReturnData();
			return array($first,$second);
		}else{
			return array($this->articles,$this->articleProImages,$this->tagInfo,$this->articleTagArr);
		}
		
	}
	public function getArticlesByChannel(){
		$articleFilter = new ArticleFilter();
		$articleFilter->select(
				array(
						ArticleFilter::CONDITION_FIELD_NAME_ID,
						ArticleFilter::CONDITION_FIELD_NAME_TITLE,
						ArticleFilter::CONDITION_FIELD_NAME_SHORTTITLE,
						ArticleFilter::CONDITION_FIELD_NAME_PUBLISHTIME,
				        ArticleFilter::CONDITION_FIELD_NAME_ARTICLE_PUBLISHID
				)
		);
		//$articleFilter->order(ArticleFilter::CONDITION_FIELD_NAME_ID,false);
		$articleFilter->order(ArticleFilter::CONDITION_FIELD_NAME_PUBLISHTIME,false);
		
		if($this->getLevel() == -2){
		    $articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_LESSEQUAL,2);
		}else{
			$bigLevel = $this->getBigLevel();
			$level = $this->getLevel();
			if(!empty($bigLevel)){
				if($bigLevel != $level){
					$articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_GREATEREQUAL,$level);
					$articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_LESSEQUAL,$bigLevel);
				}else {
					$articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_EQUAL,$level);
				}
			}else {
				$articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_GREATEREQUAL,$level);
			}  
		}
		$articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_STATUS,Condition::CONDITION_EQUAL, \haibao\cms\model\data\Article::STATUS_ENABLE);
		$articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_PUBLISHED,Condition::CONDITION_EQUAL,\haibao\cms\model\data\Article::PUBLISHED_YES);
		
		
		
		if($this->getIsDate()){
		    if($this->dateType == self::DATE_TYPE_HALFWEEK){
		        $articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_PUBLISHTIME,Condition::CONDITION_BETWEEN,array(date('Y-m-d',strtotime('-2 weeks')),date('Y-m-d')));
		    }
		}
		if($this->getIsArticleTag()){
			$articleTagFilter = new ArticleTagFilter();
			$articleTagFilter->select(
					array(
							ArticleTagFilter::CONDITION_FIELD_NAME_ARTICLE_ID,
							ArticleTagFilter::CONDITION_FIELD_NAME_TAG_ID,
							ArticleTagFilter::CONDITION_FIELD_NAME_PARENT_ID,
							ArticleTagFilter::CONDITION_FIELD_NAME_IS_PRIMAIY,
					)
			);
			if($this->getIsConditionTag()){
				if(is_array($this->getTagIds())){
					if($this->isParentTag){
						$articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_PARENT_ID,Condition::CONDITION_IN,$this->getTagIds());
					}else{
						$articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_TAG_ID,Condition::CONDITION_IN,$this->getTagIds());
					}
				}else{
					if($this->isParentTag){
						$articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_PARENT_ID,Condition::CONDITION_EQUAL,(int)$this->getTagIds());
					}else{
						$articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_TAG_ID,Condition::CONDITION_EQUAL,(int)$this->getTagIds());
					}
				}
				if($this->isPrimaryTag){
					$articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_IS_PRIMAIY,Condition::CONDITION_EQUAL,\haibao\cms\model\data\ArticleTag::PRIMAIY_IS);
				}elseif($this->primaryTag){
					$articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_TAG_ID,Condition::CONDITION_EQUAL,$this->primaryTag);
				}
			}else{
				if($this->isPrimaryTag){
					$articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_IS_PRIMAIY,Condition::CONDITION_EQUAL,\haibao\cms\model\data\ArticleTag::PRIMAIY_IS);
				}
			}
			if($this->primaryTag && $this->isPrimaryTag){
				$articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_TAG_ID,Condition::CONDITION_EQUAL,$this->primaryTag);
			}
			$articleFilter->leftJoin($articleTagFilter,null,ArticleFilter::CONDITION_FIELD_NAME_ID,ArticleTagFilter::CONDITION_FIELD_NAME_ARTICLE_ID,ArticleFilter::CONDITION_FIELD_NAME_ARTICLE_TAG,false);
		}
		if($this->getIsPage()){
			$articleFilter->setPager(new Pager($this->getLimit(), $this->getCurrentPage()));
			$this->pager = $articleFilter->getPager();
		}else{
		    $articleFilter->limit(0,$this->getLimit());
		}
		$articles = $this->articleData->getAll($articleFilter);
		
		if($this->getIsPage()){
			if($this->getCurrentPage() !=$this->pager->getCurrentPage()) {
				throw new BusinessException('文章内容为空',self::DATA_EMPTY);
			}
		}
		
		$count = count($articles);

		foreach($articles as $key=>$article){
			$article->SiteType = self::INFO_TYPE_ARTICLE;
			$publishTime = strtotime($article->PublishTime->format('Y-m-d H:i:s'))+$count-$key;
			$this->articles[$publishTime] = $article;
			array_push($this->articleIdArr,$article->Id);
		}
		if($this->getIsProImage()){
			
			if($this->articleIdArr){
				$this->articleProImages = $this->getArticleProImage($this->articleIdArr,$this->getProImageLevel());
			}
		}
		if($this->getIsReturnTag()){
			
			if($this->isParentTag){
				foreach($this->articles as $article){
					array_push($this->tagIdArr,$article->ArticleTag->TagId);
				}
				if($this->tagIdArr){
					$this->tagInfo = PublicControllerBusiness::getTagInfoById($this->tagIdArr,$this->getSource());
				}
			}else{
				if($this->articleIdArr){
					$this->articleTagArr = $this->getArticleTagByArticleId($this->articleIdArr,$this->isReturnPrimary);
					
					$tmpTagIds = array();
					if($this->isReturnPrimary){
						foreach($this->articleTagArr as $arr){
							array_push($tmpTagIds,$arr['TagId']);
						}
					}else{
						foreach($this->articleTagArr as $key=>$arr){
							$tmpTagIds = array_merge($tmpTagIds,array_reduce($arr, create_function('$v,$w', '$v[$w["TagId"]]=$w["TagId"];return $v;')));
						}
					}
					if($tmpTagIds){
						$this->tagInfo = PublicControllerBusiness::getTagInfoById(array_unique($tmpTagIds),$this->getSource());
					}
				}
			}
		}
	}
	
	/**
	 * @param Boolure $isRemoveArticle 获取图集的时候是否排除跟图集关联的资讯
	 */
	public function getImageCollByChannel($isRemoveArticle = true){
		$imageCollFilter = new ImageCollFilter();
		$imageCollFilter->select(
				array(
						ImageCollFilter::CONDITION_FIELD_NAME_ID,
						ImageCollFilter::CONDITION_FIELD_NAME_TITLE,
						ImageCollFilter::CONDITION_FIELD_NAME_SHORT_TITLE,
						ImageCollFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_PUBLISHTIME,
				)
		);
		$imageCollFilter->order(ImageCollFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_PUBLISHTIME,false);
		$imageCollFilter->limit(0,$this->getLimit());
		$bigLevel = $this->getBigLevel();
		$level = $this->getLevel();
		if(!empty($bigLevel)){
			if($bigLevel != $level){
				$imageCollFilter->where(ImageCollFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_GREATEREQUAL,$level);
				$imageCollFilter->where(ImageCollFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_LESSEQUAL,$bigLevel);
			}else {
				$imageCollFilter->where(ImageCollFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_EQUAL,$level);
			}
		}else {
			$imageCollFilter->where(ImageCollFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_GREATEREQUAL,$level);
		}

		$imageCollFilter->where(ImageCollFilter::CONDITION_FIELD_NAME_STATUS,Condition::CONDITION_EQUAL, \haibao\cms\model\data\imagecollective\ImageCollective::STATUS_ENABLE);
		$imageCollFilter->where(ImageCollFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_PUBLISHED,Condition::CONDITION_EQUAL,\haibao\cms\model\data\imagecollective\ImageCollective::STATUS_YES_PUBLISH);

		
		if($isRemoveArticle){
			if($this->articleIdArr){
				$imageCollArticleFilter = new ImageCollArticleFilter();
				if(is_array($this->articleIdArr)){
					$imageCollArticleFilter->where(ImageCollArticleFilter::CONDITION_FIELD_NAME_ARITCLE_ID, Condition::CONDITION_OR,array(
							new Condition(ImageCollArticleFilter::CONDITION_FIELD_NAME_ARITCLE_ID, Condition::CONDITION_NOTIN, $this->articleIdArr),
							new Condition(ImageCollArticleFilter::CONDITION_FIELD_NAME_ARITCLE_ID, Condition::CONDITION_IS_NULL, null),
					));
				}else{
					$imageCollArticleFilter->where(ImageCollArticleFilter::CONDITION_FIELD_NAME_ARITCLE_ID, Condition::CONDITION_OR,array(
							new Condition(ImageCollArticleFilter::CONDITION_FIELD_NAME_ARITCLE_ID, Condition::CONDITION_NOTEQUAL, $this->articleIdArr),
							new Condition(ImageCollArticleFilter::CONDITION_FIELD_NAME_ARITCLE_ID, Condition::CONDITION_IS_NULL, null),
					));
				}
				$imageCollFilter->leftjoin($imageCollArticleFilter,null,ImageCollFilter::CONDITION_FIELD_NAME_ID,ImageCollArticleFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_ID);
			}
		}
		
		if($this->getIsArticleTag()){
			$imageCollTagFilter = new ImageCollTagFilter();
			$imageCollTagFilter->select(
					array(
							ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_COLLECTIVE_ID,
							ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ID,
							ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_PARENTID,
							ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ISPRIMAIY,
					)
			);
			if($this->getIsConditionTag()){
				if(is_array($this->getTagIds())){
					if($this->isParentTag){
						$imageCollTagFilter->where(ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_PARENTID,Condition::CONDITION_IN,$this->getTagIds());
					}else{
						$imageCollTagFilter->where(ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ID,Condition::CONDITION_IN,$this->getTagIds());
					}
				}else{
					if($this->isParentTag){
						$imageCollTagFilter->where(ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_PARENTID,Condition::CONDITION_EQUAL,(int)$this->getTagIds());
					}else{
						$imageCollTagFilter->where(ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ID,Condition::CONDITION_EQUAL,(int)$this->getTagIds());
					}
				}
				if($this->isPrimaryTag){
					$imageCollTagFilter->where(ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ISPRIMAIY,Condition::CONDITION_EQUAL,\haibao\cms\model\data\imagecollective\ImageCollectiveTag::IS_PRIMAIY);
				}elseif($this->primaryTag){
					$imageCollTagFilter->where(ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ID,Condition::CONDITION_EQUAL,$this->primaryTag);
				}
			}else{
				if($this->isPrimaryTag){
					$imageCollTagFilter->where(ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ISPRIMAIY,Condition::CONDITION_EQUAL,\haibao\cms\model\data\imagecollective\ImageCollectiveTag::IS_PRIMAIY);
				}
			}

			if($this->primaryTag && $this->isPrimaryTag){
				$imageCollTagFilter->where(ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ID,Condition::CONDITION_EQUAL,$this->primaryTag);
			}
			$imageCollFilter->leftJoin($imageCollTagFilter,null,ImageCollFilter::CONDITION_FIELD_NAME_ID,ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_COLLECTIVE_ID,ImageCollFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_TAG,false);
		}
		$imageColls = $this->imageCollData->getAll($imageCollFilter);
		$count = count($imageColls);
		foreach($imageColls as $key=>$imageColl){
			$imageColl->SiteType = self::INFO_TYPE_IMAGE;
			$time = strtotime($imageColl->PublishTime->format('Y-m-d H:i:s'))+$count-$key;
			$this->imageColls[$time] = $imageColl;
			array_push($this->collIdArr,$imageColl->Id);
			
		}
		if($this->getIsProImage()){
			
			if($this->collIdArr){
				$this->collProImages = $this->getCollProImage($this->collIdArr,$this->getProImageLevel());
			}
		}
		if($this->getIsReturnTag()){
			
			if($this->isParentTag){
				foreach($this->imageColls as $coll){
					array_push($this->collTagIdArr,$coll->ImageCollectiveTag->TagId);
				}
				$this->collTagIdArr = array_flip(array_flip($this->collTagIdArr));
				if($this->collTagIdArr){
					$this->collTagInfo = PublicControllerBusiness::getTagInfoById($this->collTagIdArr);
				}
			}else{
				$this->collTagArr = $this->getCollTagByCollId($this->collIdArr,$this->isReturnPrimary);
				if($this->collTagArr){
					$tmpTagIds = array();
					if($this->isReturnPrimary){
						foreach($this->collTagArr as $arr){
							array_push($tmpTagIds,$arr['TagId']);
						}
					}else{
						foreach($this->collTagArr as $key=>$arr){
							$tmpTagIds = array_merge($tmpTagIds,array_reduce($arr, create_function('$v,$w', '$v[$w["TagId"]]=$w["TagId"];return $v;')));
						}
					}
					$this->collTagInfo = PublicControllerBusiness::getTagInfoById(array_unique($tmpTagIds),$this->getSource());
				}
			}
		}
	}
	
	
	/**
	 * 调出规则：调出?时间内?频道流量前?资讯或图集的混搭排行榜2
	 */
	public function getChannelArticleAndAtiasByClick(){
		$this->getArticleByClick();
		if($this->getIsImageColl()){
			$this->getImageCollByClick();
			return $this->packageQueryTypeChannelReturnData();
		}else{
			return array($this->articles,$this->articleProImages,$this->tagInfo,$this->articleTagArr);
		}
		
	}
	
	public function getArticleByClick(){

		$articleFilter = new ArticleFilter();
		$articlePropertyFilter = new ArticlePropertyFilter();
		$articleFilter->select(
				array(
						ArticleFilter::CONDITION_FIELD_NAME_ID,
						ArticleFilter::CONDITION_FIELD_NAME_TITLE,
						ArticleFilter::CONDITION_FIELD_NAME_SHORTTITLE,
						ArticleFilter::CONDITION_FIELD_NAME_PUBLISHTIME,
				        ArticleFilter::CONDITION_FIELD_NAME_ARTICLE_PUBLISHID,
				        ArticleFilter::CONDITION_FIELD_NAME_SUMMARY
				)
		);
		if($this->getIsDate()){
			if($this->dateType == self::DATE_TYPE_MONTH){
				$articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_PUBLISHTIME,Condition::CONDITION_BETWEEN,array(date('Y-m-d',strtotime('-1 months')),date('Y-m-d')));
			} else {
				$articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_PUBLISHTIME,Condition::CONDITION_BETWEEN,array(date('Y-m-d',strtotime('-1 week')),date('Y-m-d')));
			}
		}
		
		$articlePropertyFilter->select(
				array(
						ArticlePropertyFilter::CONDITION_FIELD_NAME_ARTICLE_ID,
						ArticlePropertyFilter::CONDITION_FIELD_NAME_CLICK_NUM,
						ArticlePropertyFilter::CONDITION_FIELD_NAME_ARTICLE_EDIT_CLICK_NUM,
						ArticlePropertyFilter::CONDITION_FIELD_NAME_ARTICLE_COMMENT_NUM
				)
		);
		$articleFilter->limit(0,$this->getLimit());
		$articleFilter->order(ArticlePropertyFilter::CONDITION_FIELD_NAME_ARTICLE_EDIT_CLICK_NUM,false,$articlePropertyFilter);
		
		$articleFilter->leftJoin($articlePropertyFilter,null,ArticleFilter::CONDITION_FIELD_NAME_ID,ArticlePropertyFilter::CONDITION_FIELD_NAME_ARTICLE_ID,ArticleFilter::CONDITION_FIELD_NAME_ARTICLE_PROPERTY,false);
			
		if($this->getIsArticleTag()){
			$articleTagFilter = new ArticleTagFilter();
			$articleTagFilter->select(
					array(
							ArticleTagFilter::CONDITION_FIELD_NAME_ARTICLE_ID,
							ArticleTagFilter::CONDITION_FIELD_NAME_TAG_ID,
							ArticleTagFilter::CONDITION_FIELD_NAME_PARENT_ID,
					)
			);
			if($this->getIsConditionTag()){
				
				if(is_array($this->getTagIds())){
					if($this->isParentTag){
						$articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_PARENT_ID,Condition::CONDITION_IN,$this->getTagIds());
						$articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_IS_PRIMAIY,Condition::CONDITION_EQUAL,\haibao\cms\model\data\ArticleTag::PRIMAIY_IS);
					}else{
						$articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_TAG_ID,Condition::CONDITION_IN,$this->getTagIds());
					}
				}else{
					if($this->isParentTag){
						$articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_PARENT_ID,Condition::CONDITION_EQUAL,(int)$this->getTagIds());
						$articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_IS_PRIMAIY,Condition::CONDITION_EQUAL,\haibao\cms\model\data\ArticleTag::PRIMAIY_IS);
					}else{
						$articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_TAG_ID,Condition::CONDITION_EQUAL,(int)$this->getTagIds());
					}
				}
			}else{
				if($this->isPrimaryTag) $articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_IS_PRIMAIY,Condition::CONDITION_EQUAL,\haibao\cms\model\data\ArticleTag::PRIMAIY_IS);
			}
			
			
			$articleFilter->leftJoin($articleTagFilter,null,ArticleFilter::CONDITION_FIELD_NAME_ID,ArticleTagFilter::CONDITION_FIELD_NAME_ARTICLE_ID,ArticleFilter::CONDITION_FIELD_NAME_ARTICLE_TAG,false);
		}
		
		$bigLevel = $this->getBigLevel();
		$level = $this->getLevel();
		if(!empty($bigLevel)){
			if($bigLevel != $level){
				$articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_GREATEREQUAL,$level);
				$articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_LESSEQUAL,$bigLevel);
			}else {
				$articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_EQUAL,$level);
			}
		}else {
			$articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_GREATEREQUAL,$level);
		}
		
		$articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_STATUS,Condition::CONDITION_EQUAL,\haibao\cms\model\data\Article::STATUS_ENABLE);
		$articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_PUBLISHED,Condition::CONDITION_EQUAL,\haibao\cms\model\data\Article::PUBLISHED_YES);

		$articlePropertyFilter->where(ArticlePropertyFilter::CONDITION_FIELD_NAME_CLICK_NUM,Condition::CONDITION_GREATER,0);
		$articles  = $this->articleData->getAll($articleFilter);
		
		foreach($articles as $article){
			$article->SiteType = self::INFO_TYPE_ARTICLE;
			$this->articles[$article->ArticleProperty->EditClickNum] = $article;
			array_push($this->articleIdArr,$article->Id);
		}
		if($this->getIsProImage()){
			if($this->articleIdArr){
				$this->articleProImages = $this->getArticleProImage($this->articleIdArr,$this->getProImageLevel());
			}
		}
		if($this->getIsReturnTag()){
			if($this->isParentTag){
				foreach($this->articles as $article){
					if(!$article->ArticleTag) continue;
					array_push($this->tagIdArr,$article->ArticleTag->TagId);
				}
				if($this->tagIdArr){
					$this->tagInfo = PublicControllerBusiness::getTagInfoById($this->tagIdArr);
				}
			}else{
				if($this->articleIdArr){
					$this->articleTagArr = $this->getArticleTagByArticleId();
					$tmpTagIds = array();
					foreach($this->articleTagArr as $arr){
						array_push($tmpTagIds,$arr['TagId']);
					}
					$this->tagInfo = PublicControllerBusiness::getTagInfoById(array_unique($tmpTagIds),$this->getSource());
				}
			}
		}
	}
	
	public function getImageCollByClick($isRemoveArticle = true){
		
		$imageCollFilter = new ImageCollFilter();
		$imageCollProperyFilter = new ImageCollPropertyFilter();
		
		$imageCollFilter->select(
				array(
						ImageCollFilter::CONDITION_FIELD_NAME_ID,
						ImageCollFilter::CONDITION_FIELD_NAME_TITLE,
						ImageCollFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_PUBLISHTIME,
						ImageCollFilter::CONDITION_FIELD_NAME_SHORT_TITLE,
				)
		);
		$imageCollProperyFilter->select(array(
			ImageCollPropertyFilter::CONDITION_FIELD_NAME_CLICK_NUM,
			ImageCollPropertyFilter::CONDITION_FIELD_NAME_IMAGE_EDITCLICK_NUM
		));
		$imageCollFilter->limit(0,$this->getLimit());
		$imageCollFilter->order(ImageCollPropertyFilter::CONDITION_FIELD_NAME_IMAGE_EDITCLICK_NUM,false,$imageCollProperyFilter);
		
		if($isRemoveArticle){
			if($this->articleIdArr){
				$imageCollArticleFilter = new ImageCollArticleFilter();
				if(is_array($this->articleIdArr)){
					$imageCollArticleFilter->where(ImageCollArticleFilter::CONDITION_FIELD_NAME_ARITCLE_ID, Condition::CONDITION_OR,array(
							new Condition(ImageCollArticleFilter::CONDITION_FIELD_NAME_ARITCLE_ID, Condition::CONDITION_NOTIN, $this->articleIdArr),
							new Condition(ImageCollArticleFilter::CONDITION_FIELD_NAME_ARITCLE_ID, Condition::CONDITION_IS_NULL, null),
					));
				}else{
					$imageCollArticleFilter->where(ImageCollArticleFilter::CONDITION_FIELD_NAME_ARITCLE_ID, Condition::CONDITION_OR,array(
							new Condition(ImageCollArticleFilter::CONDITION_FIELD_NAME_ARITCLE_ID, Condition::CONDITION_NOTEQUAL, $this->articleIdArr),
							new Condition(ImageCollArticleFilter::CONDITION_FIELD_NAME_ARITCLE_ID, Condition::CONDITION_IS_NULL, null),
					));
				}
				$imageCollFilter->leftjoin($imageCollArticleFilter,null,ImageCollFilter::CONDITION_FIELD_NAME_ID,ImageCollArticleFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_ID);
			}
		}
		
		if($this->getIsDate()){
			if($this->dateType == self::DATE_TYPE_WEEK){
				$imageCollFilter->where(ImageCollFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_PUBLISHTIME,Condition::CONDITION_BETWEEN,array(date('Y-m-d',strtotime('-1 weeks')),date('Y-m-d')));
			}elseif($this->dateType == self::DATE_TYPE_MONTH){
				$imageCollFilter->where(ImageCollFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_PUBLISHTIME,Condition::CONDITION_BETWEEN,array(date('Y-m-d',strtotime('-1 months')),date('Y-m-d')));
			}
		}
		
		if($this->getIsArticleTag()){
			
			$imageCollTagFilter = new ImageCollTagFilter();
			$imageCollTagFilter->select(
					array(
							ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_COLLECTIVE_ID,
							ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ID,
							ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_PARENTID,
					)
			);
			
			if($this->getIsConditionTag()){
				
				if(is_array($this->getTagIds())){
					if($this->isParentTag){
						$imageCollTagFilter->where(ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_PARENTID,Condition::CONDITION_IN,$this->getTagIds());
						$imageCollTagFilter->where(ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ISPRIMAIY,Condition::CONDITION_EQUAL,\haibao\cms\model\data\imagecollective\ImageCollectiveTag::IS_PRIMAIY);
					}else{
						$imageCollTagFilter->where(ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ID,Condition::CONDITION_IN,$this->getTagIds());
					}
				}else{
					if($this->isParentTag){
						$imageCollTagFilter->where(ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_PARENTID,Condition::CONDITION_EQUAL,(int)$this->getTagIds());
						$imageCollTagFilter->where(ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ISPRIMAIY,Condition::CONDITION_EQUAL,\haibao\cms\model\data\imagecollective\ImageCollectiveTag::IS_PRIMAIY);
					}else{
						$imageCollTagFilter->where(ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ID,Condition::CONDITION_EQUAL,(int)$this->getTagIds());
					}
				}
			}else{
				if($this->isPrimaryTag) $imageCollTagFilter->where(ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ISPRIMAIY,Condition::CONDITION_EQUAL,\haibao\cms\model\data\imagecollective\ImageCollectiveTag::IS_PRIMAIY);
			}
			$imageCollFilter->leftJoin($imageCollTagFilter,null,ImageCollFilter::CONDITION_FIELD_NAME_ID,ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_COLLECTIVE_ID,ImageCollFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_TAG,false);
		}
		
		$bigLevel = $this->getBigLevel();
		$level = $this->getLevel();
		if(!empty($bigLevel)){
			if($bigLevel != $level){
				$imageCollFilter->where(ImageCollFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_GREATEREQUAL,$level);
				$imageCollFilter->where(ImageCollFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_LESSEQUAL,$bigLevel);
			}else {
				$imageCollFilter->where(ImageCollFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_EQUAL,$level);
			}
		}else {
			$imageCollFilter->where(ImageCollFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_GREATEREQUAL,$level);
		}
		
		$imageCollFilter->leftJoin($imageCollProperyFilter,null,ImageCollFilter::CONDITION_FIELD_NAME_ID,ImageCollPropertyFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_ID,ImageCollFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_PRO,false);
		
		$imageCollFilter->where(ImageCollFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_PUBLISHED,Condition::CONDITION_EQUAL,\haibao\cms\model\data\imagecollective\ImageCollective::STATUS_YES_PUBLISH);

		
		$imageCollProperyFilter->where(ImageCollPropertyFilter::CONDITION_FIELD_NAME_CLICK_NUM,Condition::CONDITION_GREATER,0);
		
		$imageColls = $this->articleData->getAll($imageCollFilter);
		
		foreach($imageColls as $imageColl){
			$imageColl->SiteType = self::INFO_TYPE_IMAGE;
			$this->imageColls[$imageColl->ImageCollectivePro->EditClickNum] = $imageColl;
			array_push($this->collIdArr,$imageColl->Id);
			
		}
		if($this->getIsProImage()){
		
			if($this->collIdArr){
				$this->collProImages = $this->getCollProImage($this->collIdArr,$this->getProImageLevel());

			}
		}
		if($this->getIsReturnTag()){
			if($this->isParentTag){
				foreach($this->imageColls as $coll){
					array_push($this->collTagIdArr,$coll->ImageCollectiveTag->TagId);
				}
				$this->collTagIdArr = array_flip(array_flip($this->collTagIdArr));
				if($this->collTagIdArr ){
					$this->collTagInfo = PublicControllerBusiness::getTagInfoById($this->collTagIdArr);
				}
			}else{
				$this->collTagArr = $this->getCollTagByCollId();
				if($this->collTagArr){
					$tmpTagIds = array();
					foreach($this->collTagArr as $arr){
						array_push($tmpTagIds,$arr['TagId']);
					}
					$this->collTagInfo = PublicControllerBusiness::getTagInfoById(array_unique($this->collTagArr),$this->getSource());
				}
			}
		}
	}	
	
	/**
	 * 当前一周时间范围内，调出流量最高的两个？（品牌/明星）的资讯，并显示出相关？（品牌/明星）LOGO，每个LOGO对应两条资讯，第二条资讯仅显示标题文字链3
	 * @param number $limit 文章的个数
	 * @return multitype:multitype:NULL string unknown Ambigous <>  unknown
	 */
	public function getChannelArticleToBrandOrStar(){
		
		$publicControllerData = new PublicControllerData();
		if($this->getRelType() == 1){

			$queryCondition['tableName'] = 'Brand';
		}else{
			$queryCondition['tableName'] = 'Celebrity';
		}

		$queryCondition['startDate'] = date('Y-m-d H:i:s',time());
		$queryCondition['Status'] = 1;
		$queryCondition['limit'] = $this->limit?$this->limit:2;
		
		// 获取两个品牌/明星的文章 标签ID作为KEY
		$this->articles = $publicControllerData->getChannelArticleToBrandOrStar($queryCondition);
		$relIdArr = $brandImgIds = $tagIdArr = $finalArticleArr = $relData = array();
		if($this->articles){
			foreach($this->articles as $key=>$article){
				array_push($this->articleIdArr,$article['ArticleId']);
				array_push($tagIdArr,$article['TagId']);
				
				if(!isset($finalArticleArr[$article['TagId']])){
					$finalArticleArr[$article['TagId']] = array();
				}
				array_push($finalArticleArr[$article['TagId']],$article);

				list($otherArticle,$articleId,$tagId) = $publicControllerData->getArticlesByTagIds($article['TagId'],$article['ArticleId']);
				if(!empty($otherArticle)){
					array_push($finalArticleArr[$tagId],$otherArticle[$tagId]);
					array_push($this->articleIdArr,$articleId);
				}
			}
			// DO : 获取标签下对应的品牌/明星 标签ID作为KEY
			$relData = $publicControllerData->getRelDataByTagIds($tagIdArr,$this->getRelType());
			
			if($this->getIsProImage()){
				
				$this->articleProImages = $this->getArticleProImage($this->articleIdArr,$this->getProImageLevel());
			}
			
			// DO : 将品牌/明星数据与文章数据关联
			foreach($relData as $key=>$data){
				
				if(!isset($data['Url'])) $relData[$key]['Url'] = '';
				if(isset($finalArticleArr[$key])){
					
					foreach($finalArticleArr[$key] as $_k=>$_v){
						if(isset($this->articleProImages[$_v['ArticleId']][$this->getProImageLevel()])){
							 $finalArticleArr[$key][$_k]['ProImage'] = $this->articleProImages[$_v['ArticleId']][$this->getProImageLevel()];
						}else{
							if(isset($this->articleProImages[$_v['ArticleId']][\haibao\cms\model\data\ArticleProImage::Level_ZERO])){
								$finalArticleArr[$key][$_k]['ProImage'] = $this->articleProImages[$_v['ArticleId']][\haibao\cms\model\data\ArticleProImage::Level_ZERO];
							}else{
								$finalArticleArr[$key][$_k]['ProImage'] = \haibao\cms\business\control\PublicController::getArticleFirstImage($_v['ArticleId']);
							}
						}
					}

					$relData[$key]['ArticleInfo'] = $finalArticleArr[$key];
				}else{
					$relData[$key]['ArticleInfo'] = array();
				}

				array_push($brandImgIds,$data['ImgId']);
				array_push($relIdArr,$data['Id']);
			}
			
			if($this->getRelType() == 1){
				$imageData = new \haibao\cms\data\ImageLibrary();
				$imageModels = $imageData->getImageById($brandImgIds);	
							
				foreach($relData as $key=>$info){
					$relData[$key]['StaticPicUrl'] = '';
					foreach($imageModels as $imageInfo){
						if($imageInfo->Id == $info['ImgId']){
							$relData[$key]['StaticPicUrl'] = $imageInfo->Filename;
							break;
						}
					}	
				}
			}elseif($this->getRelType() == 2){
		
				$celebrityImageFilter = new CelebrityImageFilter();
				$celebrityImageFilter->select(array(CelebrityImageFilter::CONDITION_FIELD_NAME_CELEBRITY_ID));
		
				$imageLibraryFilter = new ImageLibraryFitler();
				$imageLibraryFilter->select(array(ImageLibraryFitler::CONDITION_FIELD_NAME_FILENAME));
		
				$celebrityImageFilter->leftJoin($imageLibraryFilter,null,CelebrityImageFilter::CONDITION_FIELD_NAME_IMAGE_ID,ImageLibraryFitler::CONDITION_FIELD_NAME_ID,CelebrityImageFilter::CONDITION_FIELD_NAME_ORIGINAL_IMAGE_URL,false);
				$celebrityImageFilter->where(CelebrityImageFilter::CONDITION_FIELD_NAME_CELEBRITY_ID,Condition::CONDITION_IN,$relIdArr);
				$celebrityImageFilter->where(CelebrityImageFilter::CONDITION_FIELD_NAME_IMAGE_TYPE,Condition::CONDITION_EQUAL,\haibao\cms\model\data\CelebrityImage::IMAGE_TYPE_PICTURE);
		
				$celebrityImageInfo = \haibao\cms\business\Celebrity::getAll($celebrityImageFilter);
				
				foreach($relData as $key => $data){
					$relData[$key]['StaticPicUrl'] = "";
					foreach($celebrityImageInfo as $info){
						if($info->CelebrityId == $data['Id']){
							$relData[$key]['StaticPicUrl'] = $info->OriginalImageUrl->Filename;
							break;
						}
					}
				}
						
			}
		}
		return $relData;
		
	}
	
	/**
	 * 最近一周时间范围内，全站？级图集中，浏览量最高的前？个。 单独的一个方法4
	 */
	public function getImageCollectiveByClick(){
		$notIn = $imageColls = $complateImageColls = array();
		$imageColls = $this->getImageCollForEnoughWeekData($notIn,true,$this->getLimit());
		if(count($imageColls) < $this->getLimit()){
			$limit = $this->getLimit()-count($imageColls);
			foreach($imageColls as $coll){
				array_push($notIn,$coll->Id);
			}
			$complateImageColls = $this->getImageCollForEnoughWeekData($notIn,false,$limit);
		}
		if($complateImageColls){
			foreach ($complateImageColls as $data){
				array_push($imageColls,$data);
			}
		}
		if($this->getIsProImage()){
			foreach($imageColls as $coll){
				array_push($this->collIdArr,$coll->Id);
				array_push($this->collTagIdArr,$coll->ImageCollectiveTag->TagId);
				$coll->SiteType = self::INFO_TYPE_IMAGE;
			}
			if($this->collIdArr){
				$this->collProImages = $this->getCollProImage($this->collIdArr,$this->getProImageLevel());
			}
		}
		$this->collTagInfo = PublicControllerBusiness::getTagInfoById($this->collTagIdArr);
		return array($imageColls,$this->collProImages,$this->collTagInfo);
	}
	
	private function getImageCollForEnoughWeekData($notIn=array(),$enough=true,$limit){
		
		$this->proImageLevel = (array)$this->proImageLevel;
		$proImageArr = array();
		$imageCollFilter = new ImageCollFilter();
		$imageCollFilter->select(
				array(
						ImageCollFilter::CONDITION_FIELD_NAME_ID,
						ImageCollFilter::CONDITION_FIELD_NAME_TITLE,
						ImageCollFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_PUBLISHTIME,
						ImageCollFilter::CONDITION_FIELD_NAME_SHORT_TITLE,
				)
		);
		$imageCollFilter->limit($this->getOffset(),$limit);
		if($enough){
			if($this->getIsDate()){
				if($this->dateType == self::DATE_TYPE_WEEK){
					$imageCollFilter->where(ImageCollFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_PUBLISHTIME,Condition::CONDITION_BETWEEN,array(date('Y-m-d',strtotime('-1 weeks')),date('Y-m-d',strtotime('1 days'))));
				}
			}
		}else{
			if($this->getIsDate()){
				$imageCollFilter->where(ImageCollFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_PUBLISHTIME,Condition::CONDITION_BETWEEN,array(date('Y-m-d',strtotime('-1 month')),date('Y-m-d',strtotime('1 days'))));
			}
		}
		if($notIn){
			$imageCollFilter->where(ImageCollFilter::CONDITION_FIELD_NAME_ID, Condition::CONDITION_NOTIN, $notIn);
		}
		// isArticleTag = true 表示通过频道搜索 否则全站搜索
		if($this->getIsArticleTag()){
			$imageCollTagFilter = new ImageCollTagFilter();
			$imageCollTagFilter->select(
					array(
							ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_COLLECTIVE_ID,
							ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ID,
							ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_PARENTID,
					)
			);
			if(is_array($this->getTagIds())){
				if($this->isParentTag){
					$imageCollTagFilter->where(ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_PARENTID,Condition::CONDITION_IN,$this->getTagIds());
					$imageCollTagFilter->where(ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ISPRIMAIY,Condition::CONDITION_EQUAL,\haibao\cms\model\data\imagecollective\ImageCollectiveTag::IS_PRIMAIY);
				}else{
					$imageCollTagFilter->where(ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ID,Condition::CONDITION_IN,$this->getTagIds());
				}
			}else{
				if($this->isParentTag){
					$imageCollTagFilter->where(ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_PARENTID,Condition::CONDITION_EQUAL,(int)$this->getTagIds());
					$imageCollTagFilter->where(ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ISPRIMAIY,Condition::CONDITION_EQUAL,\haibao\cms\model\data\imagecollective\ImageCollectiveTag::IS_PRIMAIY);
				}else{
					$imageCollTagFilter->where(ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ID,Condition::CONDITION_EQUAL,(int)$this->getTagIds());
				}
			}
			$imageCollFilter->leftJoin($imageCollTagFilter,null,ImageCollFilter::CONDITION_FIELD_NAME_ID,ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_COLLECTIVE_ID,ImageCollFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_TAG,false);
		} else {
			$imageCollTagFilter = new ImageCollTagFilter();
			$imageCollTagFilter->select(
					array(
							ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_COLLECTIVE_ID,
							ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ID,
							ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_PARENTID,
					)
			);
			$imageCollTagFilter->where(ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ISPRIMAIY,Condition::CONDITION_EQUAL,\haibao\cms\model\data\imagecollective\ImageCollectiveTag::IS_PRIMAIY);
			$imageCollFilter->leftJoin($imageCollTagFilter,null,ImageCollFilter::CONDITION_FIELD_NAME_ID,ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_COLLECTIVE_ID,ImageCollFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_TAG,false);
		}
		
		if($this->getOrderByNew()){
			$imageCollFilter->order(ImageCollFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_PUBLISHTIME,false);
		}else{
			$imageCollProperyFilter = new ImageCollPropertyFilter();
			$imageCollFilter->order(ImageCollPropertyFilter::CONDITION_FIELD_NAME_CLICK_NUM,false,$imageCollProperyFilter);
			$imageCollFilter->leftJoin($imageCollProperyFilter,null,ImageCollFilter::CONDITION_FIELD_NAME_ID,ImageCollPropertyFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_ID,ImageCollFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_PRO,false);
		}
		
		
		$imageCollFilter->where(ImageCollFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_PUBLISHED,Condition::CONDITION_EQUAL,\haibao\cms\model\data\imagecollective\ImageCollective::STATUS_YES_PUBLISH);
		
		
		$bigLevel = $this->getBigLevel();
		$level = $this->getLevel();
		if(!empty($bigLevel)){
			if($bigLevel != $level){
				$imageCollFilter->where(ImageCollFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_GREATEREQUAL,$level);
				$imageCollFilter->where(ImageCollFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_LESSEQUAL,$bigLevel);
			}else {
				$imageCollFilter->where(ImageCollFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_EQUAL,$level);
			}
		}else {
			$imageCollFilter->where(ImageCollFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_GREATEREQUAL,$level);
		}
		
		$imageColls = $this->articleData->getAll($imageCollFilter);
		if($this->getIsProImage()){
			
			foreach($imageColls as $coll){
				array_push($this->collIdArr,$coll->Id);
				$coll->SiteType = self::INFO_TYPE_IMAGE;
			}
			if($this->collIdArr){
				$this->collProImages = $this->getCollProImage($this->collIdArr,$this->getProImageLevel());
			}
		}
		return $imageColls;
	}
	/**
	 * 获取最新的资讯/图集列表 存在分页数据 5
	 */
	public function getListByNew(){
		$this->getArticlesByNew();
		if($this->getIsImageColl()){
			$this->getCollListByNew();
			return $this->packageQueryTypeChannelReturnData();
		}else{
			return array($this->articles,$this->articleProImages,$this->tagInfo,$this->articleTagArr,$this->pager);
		}
	}
	
	public function getArticlesByNew(){
		$articleFilter = new ArticleFilter();
		$articleFilter->select(
				array(
						ArticleFilter::CONDITION_FIELD_NAME_ID,
						ArticleFilter::CONDITION_FIELD_NAME_TITLE,
						ArticleFilter::CONDITION_FIELD_NAME_SHORTTITLE,
						ArticleFilter::CONDITION_FIELD_NAME_PUBLISHTIME,
				        ArticleFilter::CONDITION_FIELD_NAME_ARTICLE_PUBLISHID
				)
		);
		$articleFilter->order(ArticleFilter::CONDITION_FIELD_NAME_PUBLISHTIME,false);
		$bigLevel = $this->getBigLevel();
		$level = $this->getLevel();
		if(!empty($bigLevel)){
			if($bigLevel != $level){
				$articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_GREATEREQUAL,$level);
				$articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_LESSEQUAL,$bigLevel);
			}else {
				$articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_EQUAL,$level);
			}
		}else {
			$articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_GREATEREQUAL,$level);
		}
		
		$articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_PUBLISHED,Condition::CONDITION_EQUAL,\haibao\cms\model\data\Article::PUBLISHED_YES);
		$articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_STATUS,Condition::CONDITION_EQUAL,\haibao\cms\model\data\Article::STATUS_ENABLE);

		if($this->isCalendarData){
			$calendarFilter = new \haibao\cms\model\filter\CalendarIndex();
			$articleFilter->innerJoin($calendarFilter,null,$articleFilter::CONDITION_FIELD_NAME_ID,$calendarFilter::CONDITION_FIELD_NAME_ARTICLE_ID);
		}else{
			if($this->getIsArticleTag()){
				$articleTagFilter = new ArticleTagFilter();
				$articleTagFilter->select(
					array(
						ArticleTagFilter::CONDITION_FIELD_NAME_ID,
						ArticleTagFilter::CONDITION_FIELD_NAME_ARTICLE_ID,
						ArticleTagFilter::CONDITION_FIELD_NAME_TAG_ID,
						ArticleTagFilter::CONDITION_FIELD_NAME_PARENT_ID,
						ArticleTagFilter::CONDITION_FIELD_NAME_IS_PRIMAIY,
					)
				);
				if($this->getIsConditionTag()){
					if(is_array($this->getTagIds())){
						if($this->isParentTag){
							$articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_PARENT_ID,Condition::CONDITION_IN,$this->getTagIds());
						}else{
							$articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_TAG_ID,Condition::CONDITION_IN,$this->getTagIds());
						}
					}else{
						if($this->isParentTag){
							$articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_PARENT_ID,Condition::CONDITION_EQUAL,(int)$this->getTagIds());
						}else{
							$articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_TAG_ID,Condition::CONDITION_EQUAL,(int)$this->getTagIds());
						}
					}
					if($this->isPrimaryTag){
						$articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_IS_PRIMAIY,Condition::CONDITION_EQUAL,\haibao\cms\model\data\ArticleTag::PRIMAIY_IS);
					}
				}else{
					if($this->isPrimaryTag){
						$articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_IS_PRIMAIY,Condition::CONDITION_EQUAL,\haibao\cms\model\data\ArticleTag::PRIMAIY_IS);
					}
				}
				$articleFilter->leftJoin($articleTagFilter,null,ArticleFilter::CONDITION_FIELD_NAME_ID,ArticleTagFilter::CONDITION_FIELD_NAME_ARTICLE_ID,ArticleFilter::CONDITION_FIELD_NAME_ARTICLE_TAG,false);
			}
		}

		$articleFilter->setPager(new Pager($this->getLimit(), $this->getCurrentPage()));
		$this->pager = $articleFilter->getPager();
		$articles = $this->articleData->getAll($articleFilter);
		
		
		// 判断当前页是否有数据
		if($this->getCurrentPage() !=$this->pager->getCurrentPage()) {
	        throw new BusinessException('文章内容为空',self::DATA_EMPTY);
		}
		
		$count = count($articles);
		foreach($articles as $key=>$article){
			$article->SiteType = self::INFO_TYPE_ARTICLE;
			$publishTime = strtotime($article->PublishTime->format('Y-m-d H:i:s'))+$count-$key;
			$this->articles[$publishTime] = $article;
			array_push($this->articleIdArr,$article->Id);
		}
		if($this->getIsProImage()){
			if($this->articleIdArr){
				$this->articleProImages = $this->getArticleProImage($this->articleIdArr,$this->getProImageLevel());
			}
		}
	
		if($this->getIsReturnTag()){
			
			if($this->isParentTag){
				foreach($this->articles as $article){
					array_push($this->tagIdArr,$article->ArticleTag->TagId);
				}
				if($this->tagIdArr){
					$this->tagInfo = PublicControllerBusiness::getTagInfoById($this->tagIdArr);
				}
			}else{

				if($this->articleIdArr){
					$this->articleTagArr = $this->getArticleTagByArticleId(array(),$this->isReturnPrimary);
					$tmpTagIds = array();
					if($this->isReturnPrimary){
						foreach($this->articleTagArr as $arr){
							array_push($tmpTagIds,$arr['TagId']);
						}
					}else{
						foreach($this->articleTagArr as $key=>$arr){
							$tmpTagIds = array_merge($tmpTagIds,array_reduce($arr, create_function('$v,$w', '$v[$w["TagId"]]=$w["TagId"];return $v;')));
						}
					}
					$this->tagInfo = PublicControllerBusiness::getTagInfoById(array_unique($tmpTagIds),$this->getSource());
				}
			}
		}
	}
	
	/**
	 * @param Boolure $isRemoveArticle 获取图集的时候是否排除跟图集关联的资讯
	 */
	public function getCollListByNew($isRemoveArticle = true){
		$imageCollFilter = new ImageCollFilter();
		$imageCollFilter->select(
				array(
						ImageCollFilter::CONDITION_FIELD_NAME_ID,
						ImageCollFilter::CONDITION_FIELD_NAME_TITLE,
						ImageCollFilter::CONDITION_FIELD_NAME_SHORT_TITLE,
						ImageCollFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_PUBLISHTIME,
				)
		);
		$imageCollFilter->order(ImageCollFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_PUBLISHTIME,false);
		
		
		$bigLevel = $this->getBigLevel();
		$level = $this->getLevel();
		if(!empty($bigLevel)){
			if($bigLevel != $level){
				$imageCollFilter->where(ImageCollFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_GREATEREQUAL,$level);
				$imageCollFilter->where(ImageCollFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_LESSEQUAL,$bigLevel);
			}else {
				$imageCollFilter->where(ImageCollFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_EQUAL,$level);
			}
		}else {
			$imageCollFilter->where(ImageCollFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_GREATEREQUAL,$level);
		}
		$imageCollFilter->where(ImageCollFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_PUBLISHED,Condition::CONDITION_IN,array(\haibao\cms\model\data\imagecollective\ImageCollective::STATUS_YES_PUBLISH,4));
	
		if($isRemoveArticle){
			if($this->articleIdArr){
				$imageCollArticleFilter = new ImageCollArticleFilter();
				if(is_array($this->articleIdArr)){
					$imageCollArticleFilter->where(ImageCollArticleFilter::CONDITION_FIELD_NAME_ARITCLE_ID, Condition::CONDITION_OR,array(
							new Condition(ImageCollArticleFilter::CONDITION_FIELD_NAME_ARITCLE_ID, Condition::CONDITION_NOTIN, $this->articleIdArr),
							new Condition(ImageCollArticleFilter::CONDITION_FIELD_NAME_ARITCLE_ID, Condition::CONDITION_IS_NULL, null),
					));
				}else{
					$imageCollArticleFilter->where(ImageCollArticleFilter::CONDITION_FIELD_NAME_ARITCLE_ID, Condition::CONDITION_OR,array(
							new Condition(ImageCollArticleFilter::CONDITION_FIELD_NAME_ARITCLE_ID, Condition::CONDITION_NOTEQUAL, $this->articleIdArr),
							new Condition(ImageCollArticleFilter::CONDITION_FIELD_NAME_ARITCLE_ID, Condition::CONDITION_IS_NULL, null),
					));
				}
				$imageCollFilter->leftjoin($imageCollArticleFilter,null,ImageCollFilter::CONDITION_FIELD_NAME_ID,ImageCollArticleFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_ID);
			}
		}
		if($this->getIsArticleTag()){
			$imageCollTagFilter = new ImageCollTagFilter();
			$imageCollTagFilter->select(
					array(
							ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_COLLECTIVE_ID,
							ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ID,
							ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_PARENTID,
							ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ISPRIMAIY,
					)
			);
			if($this->getIsConditionTag()){
				if(is_array($this->getTagIds())){
					if($this->isParentTag){
						$imageCollTagFilter->where(ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_PARENTID,Condition::CONDITION_IN,$this->getTagIds());
					}else{
						$imageCollTagFilter->where(ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ID,Condition::CONDITION_IN,$this->getTagIds());
					}
				}else{
					if($this->isParentTag){
						$imageCollTagFilter->where(ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_PARENTID,Condition::CONDITION_EQUAL,(int)$this->getTagIds());
					}else{
						$imageCollTagFilter->where(ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ID,Condition::CONDITION_EQUAL,(int)$this->getTagIds());
					}
				}
				if($this->isPrimaryTag){
					$imageCollTagFilter->where(ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ISPRIMAIY,Condition::CONDITION_EQUAL,\haibao\cms\model\data\imagecollective\ImageCollectiveTag::IS_PRIMAIY);
				}
			}else{
				if($this->isPrimaryTag){
					$imageCollTagFilter->where(ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ISPRIMAIY,Condition::CONDITION_EQUAL,\haibao\cms\model\data\imagecollective\ImageCollectiveTag::IS_PRIMAIY);
				}
			}
			$imageCollFilter->leftJoin($imageCollTagFilter,null,ImageCollFilter::CONDITION_FIELD_NAME_ID,ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_COLLECTIVE_ID,ImageCollFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_TAG,false);
		}
        if($this->getIsPage()){
            $imageCollFilter->setPager(new Pager($this->getLimit(), $this->getCurrentPage()));
        }else{
            $imageCollFilter->limit(0,$this->getLimit());$bigLevel = $this->getBigLevel();
        }
		
		$imageColls = $this->imageCollData->getAll($imageCollFilter);

		$count = count($imageColls);
		foreach($imageColls as $key=>$imageColl){
			$imageColl->SiteType = self::INFO_TYPE_IMAGE;
			$time = strtotime($imageColl->PublishTime->format('Y-m-d H:i:s'))+$count-$key;
			$this->imageColls[$time] = $imageColl;
			array_push($this->collIdArr,$imageColl->Id);	
		}
		
		if($this->getIsProImage()){
	
			if($this->collIdArr){
				$this->collProImages = $this->getCollProImage($this->collIdArr,$this->getProImageLevel());
			}
		}
		
		if($this->getIsReturnTag()){
			
			if($this->collIdArr){
				$this->collTagArr = $this->getCollTagByCollId(array(),$this->isReturnPrimary);
				$tmpTagIds = array();
				
				if($this->isReturnPrimary){
					foreach($this->collTagArr as $arr){
						array_push($tmpTagIds,$arr['TagId']);
					}
				}else{
					foreach($this->collTagArr as $arr){
						$tmpTagIds = array_merge($tmpTagIds,array_reduce($arr, create_function('$v,$w', '$v[$w["TagId"]]=$w["TagId"];return $v;')));
					}
				}
				$this->collTagInfo = PublicControllerBusiness::getTagInfoById(array_unique($tmpTagIds),$this->getSource());
			}
		}
	}
	/**
	 * @param Array $articleId 外部调用传递的文章ID
	 * @param Boolure $isReturnPrimaryTag
	 */
	public function getArticleTagByArticleId($articleId = '',$isReturnPrimaryTag = true){

		$articleTagFilter = new ArticleTagFilter();
		$articleTagFilter->select(
				array(
						ArticleTagFilter::CONDITION_FIELD_NAME_ARTICLE_ID,
						ArticleTagFilter::CONDITION_FIELD_NAME_TAG_ID,
						ArticleTagFilter::CONDITION_FIELD_NAME_PARENT_ID,
						ArticleTagFilter::CONDITION_FIELD_NAME_IS_PRIMAIY,
				)
		);
		if($articleId){
			$articleId = (array)$articleId;
			$articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_ARTICLE_ID,Condition::CONDITION_IN,$articleId);
		}else{
			$articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_ARTICLE_ID,Condition::CONDITION_IN,$this->articleIdArr);
		}
	
		$articleTags = $this->articleData->getAll($articleTagFilter);
		$articleTagArr = array();
		if($articleTags){
			foreach($articleTags as $articleTag){
	
				if(!isset($articleTagArr[$articleTag->ArticleId])){
					$articleTagArr[$articleTag->ArticleId] = array();
				}
				if($isReturnPrimaryTag){
					if($articleTag->IsPrimaiy == \haibao\cms\model\data\ArticleTag::PRIMAIY_IS){
						$articleTagArr[$articleTag->ArticleId]['TagId'] = $articleTag->TagId;
						$articleTagArr[$articleTag->ArticleId]['ParentId'] = $articleTag->ParentId;
					}
					
				}else{
	
					$temp = array();
					$temp['TagId'] = $articleTag->TagId;
					$temp['ParentId'] = $articleTag->ParentId;
					$temp['IsPrimaiy'] = $articleTag->IsPrimaiy;
					if(!isset($articleTagArr[$articleTag->ArticleId])) $articleTagArr[$articleTag->ArticleId] = array();
					$articleTagArr[$articleTag->ArticleId][] = $temp;
				}
			}
		}
		
		foreach($articleTagArr as $key=>$val){
			if(empty($val)) {
				$articleTagArr[$key]['TagId'] = self::HAI_BAO_WANG_TAG;
				$articleTagArr[$key]['ParentId'] = self::HAI_BAO_WANG_TAG;
			}

		}
		return $articleTagArr;
	}

	/**
	 * @param Array $collId 外部调用传递的文章ID
	 * @param Boolure $isReturnPrimaryTag
	 */
	public function getCollTagByCollId($collId = '',$isReturnPrimaryTag = true){
		$collTagArr = array();
		
		$imageCollTagFilter = new ImageCollTagFilter();
		$imageCollTagFilter->select(
				array(
						ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_COLLECTIVE_ID,
						ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ID,
						ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_PARENTID,
						ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ISPRIMAIY,
				)
		);
		if($collId){
			$collId = (array)$collId;
			$imageCollTagFilter->where(ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_COLLECTIVE_ID,Condition::CONDITION_IN,$collId);
		}else{
				
			if(!$this->collIdArr){
				return $collTagArr;
			}
			$imageCollTagFilter->where(ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_COLLECTIVE_ID,Condition::CONDITION_IN,$this->collIdArr);
		}
	
		$collTags = $this->articleData->getAll($imageCollTagFilter);
		$collTagArr = array();
		if($collTags){
			foreach($collTags as $collTag){

				if($isReturnPrimaryTag){
					if($collTag->IsPrimaiy == \haibao\cms\model\data\imagecollective\ImageCollectiveTag::IS_PRIMAIY){
						$collTagArr[$collTag->ImageCollectiveId]['TagId'] = $collTag->TagId;
						$collTagArr[$collTag->ImageCollectiveId]['ParentId'] = $collTag->ParentId;
					}
				}else{

					if(!isset($collTagArr[$collTag->ImageCollectiveId])){
						$collTagArr[$collTag->ImageCollectiveId] = array();
					}
                    
					$temp = array();
					$temp['TagId'] = $collTag->TagId;
					$temp['ParentId'] = $collTag->ParentId;
					$temp['IsPrimaiy'] = $collTag->IsPrimaiy;
					$collTagArr[$collTag->ImageCollectiveId][] = $temp;
					
				}
			}
		}
		foreach($collTagArr as $key=>$val){
			if(empty($val)) $collTagArr[$key] = self::HAI_BAO_WANG_TAG;
		}
		return $collTagArr;
	}
	/**
	 * 根据文章ID获取文章
	 * @param : Array $aIds 文章ID数组
	 * @param : array $topId 频道顶级Id
	 *
	 */
	public function getArticleByIds($aIds,$topId=null,$level=0){
	    $articleFilter = new ArticleFilter();
	    $articleFilter->select(
	        array(
	            ArticleFilter::CONDITION_FIELD_NAME_ID,
	            ArticleFilter::CONDITION_FIELD_NAME_TITLE,
	            ArticleFilter::CONDITION_FIELD_NAME_SHORTTITLE,
	            ArticleFilter::CONDITION_FIELD_NAME_PUBLISHTIME,
	            ArticleFilter::CONDITION_FIELD_NAME_ARTICLE_PUBLISHID
	        )
	    );
	    $articleFilter->order(ArticleFilter::CONDITION_FIELD_NAME_ID,false);
	    $articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_ID, Condition::CONDITION_IN, $aIds);
	    $articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_LEVEL, Condition::CONDITION_GREATER, $level);
	    $articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_PUBLISHED, Condition::CONDITION_EQUAL, \haibao\cms\model\data\Article::PUBLISHED_YES);
	    $articleTagFilter = new ArticleTagFilter();
	    $articleTagFilter->select(
	        array(
	            ArticleTagFilter::CONDITION_FIELD_NAME_ARTICLE_ID,
	            ArticleTagFilter::CONDITION_FIELD_NAME_TAG_ID,
	            ArticleTagFilter::CONDITION_FIELD_NAME_PARENT_ID,
	            ArticleTagFilter::CONDITION_FIELD_NAME_IS_PRIMAIY,
	        )
	    );
	   if(!empty($topId)){
	   		if(is_array($topId)){
	   			$articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_PARENT_ID,Condition::CONDITION_IN,$topId);
	   		} else {
	   			$articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_PARENT_ID,Condition::CONDITION_EQUAL,$topId);
	   		}
	        $articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_IS_PRIMAIY,Condition::CONDITION_EQUAL,\haibao\cms\model\data\ArticleTag::PRIMAIY_IS);
	   }
	   $articleFilter->leftJoin($articleTagFilter,null,ArticleFilter::CONDITION_FIELD_NAME_ID,ArticleTagFilter::CONDITION_FIELD_NAME_ARTICLE_ID,ArticleFilter::CONDITION_FIELD_NAME_ARTICLE_TAG,false);
	   
	   $articles = \haibao\cms\business\Article::getArticleList($articleFilter);
	   $articleProImages = $this->getArticleProImage($aIds, \haibao\cms\model\data\ArticleProImage::Level_FIVE);
	   
	   foreach($articles as $key=>$article){
	   		$article->SiteType = self::INFO_TYPE_ARTICLE;
	       if(isset($articleProImages[$article->Id][\haibao\cms\model\data\ArticleProImage::Level_FIVE])){
	           $article->ArticleProImage = $articleProImages[$article->Id][\haibao\cms\model\data\ArticleProImage::Level_FIVE];
	       }else{
	           if(isset($articleProImages[$article->Id][\haibao\cms\model\data\ArticleProImage::Level_ZERO])){
	               $article->ArticleProImage = $articleProImages[$article->Id][\haibao\cms\model\data\ArticleProImage::Level_ZERO];
	           } else {
	           		$article->ArticleProImage = \haibao\cms\business\control\PublicController::getArticleFirstImage($article->Id);
	           }
	       }
	   }
	   return $articles;
	}
	
	/**
	 * 获取文章导读图
	 * @param : Int $topId 频道顶级标签Id
	 *
	 */
	public function getHotVoteByChannel($topId,$voteTagId){
	    $articleTagFilter = new ArticleTagFilter();
	    $articleTagFilter->select(
	        array(
	            ArticleTagFilter::CONDITION_FIELD_NAME_ARTICLE_ID,
	            ArticleTagFilter::CONDITION_FIELD_NAME_TAG_ID,
	            ArticleTagFilter::CONDITION_FIELD_NAME_PARENT_ID,
	            ArticleTagFilter::CONDITION_FIELD_NAME_IS_PRIMAIY,
	        )
	    );
	    $articleTagFilter->limit(0,200);
	    $articleTagFilter->order(ArticleTagFilter::CONDITION_FIELD_NAME_ID,false);
	    //$articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_PARENT_ID,Condition::CONDITION_EQUAL,$voteId);
	    $articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_TAG_ID,Condition::CONDITION_EQUAL,$voteTagId);
	    //$articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_IS_PRIMAIY,Condition::CONDITION_EQUAL,\haibao\cms\model\data\ArticleTag::PRIMAIY_IS);
	    $articleTags = \haibao\cms\business\Article::getArticleList($articleTagFilter);
	    
	    $articleIds = array();
	    foreach ($articleTags as $key=>$tag){
	        array_push($articleIds, $tag->ArticleId); 
	    }
	    $articles = $this->getArticleByIds($articleIds,$topId,2);
	    if(count($articles) >= 4){
	       $articles = array_slice($articles, 0,3);  
	    }
	    return $articles;
	}
	
	/**
	 * 获取文章导读图
	 * @param : Array $articleIdArr 文章ID数组
	 * @param : Array $level 导读图等级
	 *
	 */
	public function getArticleProImage($articleIdArr,$proImageLevel){
		
		if(!is_array($proImageLevel)) $proImageLevel = (array)$proImageLevel;
		
		$articleProImageFilter = new ArticleProImageFilter();
		$articleProImageFilter->select(
			array(
				ArticleProImageFilter::CONDITION_FIELD_NAME_ARTICLE_ID,
				ArticleProImageFilter::CONDITION_FIELD_NAME_LEVEL,
				ArticleProImageFilter::CONDITION_FIELD_NAME_PIC_URL,
			)
		);
		$articleProImageFilter->where(ArticleProImageFilter::CONDITION_FIELD_NAME_PIC_TYPE,Condition::CONDITION_EQUAL,\haibao\cms\model\data\ArticleProImage::PIC_TYPE_INTRO);
		array_push($proImageLevel,\haibao\cms\model\data\ArticleProImage::Level_ZERO);
		$articleProImageFilter->where(ArticleProImageFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_IN,$proImageLevel);
		$articleProImageFilter->where(ArticleProImageFilter::CONDITION_FIELD_NAME_ARTICLE_ID,Condition::CONDITION_IN,$articleIdArr);
	
		$articleProImages = \haibao\cms\business\Article::getArticleList($articleProImageFilter);
		$proImageArr = array();
		$articleIds = array();
		foreach($articleProImages as $proImage){
			if(isset($proImageArr[$proImage->ArticleId])){
				$proImageArr[$proImage->ArticleId][$proImage->Level] = $proImage->PicUrl;
			}else{
				$proImageArr[$proImage->ArticleId] = array();
				$proImageArr[$proImage->ArticleId][$proImage->Level] = $proImage->PicUrl;
			}
			$articleIds[] = $proImage->ArticleId;
		}
		
		$articleDiffIds = array_diff($articleIdArr, $articleIds);
		if($articleDiffIds){
			foreach ($articleDiffIds as $articleId){
				$proImageArr[$articleId] = array();
				$proImageArr[$articleId][\haibao\cms\model\data\ArticleProImage::Level_ZERO] = \haibao\cms\business\control\PublicController::getArticleFirstImage($articleId);
			}
		}
		
		return $proImageArr;
	}
	
	/**
	 * 获取图集导读图
	 * @param : Array $articleIdArr 文章ID数组
	 * @param : Array $level 导读图等级
	 *
	 */
	public function getCollProImage($collIdArr,$proImageLevel){
		if(!is_array($proImageLevel)) $proImageLevel = (array)$proImageLevel;
		if(!is_array($collIdArr)) $collIdArr = (array)$collIdArr;
		$imageCollProFilter = new ImageCollProFilter();
		$imageCollProFilter->select(
				array(
					ImageCollProFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_ID,
					ImageCollProFilter::CONDITION_FIELD_NAME_IMAGE_IMAGE_TYPE,
					ImageCollProFilter::CONDITION_FIELD_NAME_IMAGE_ID,
				)
		);
		$imageLibraryFilter = new ImageLibraryFitler();
		$imageLibraryFilter->select(array(
				ImageLibraryFitler::CONDITION_FIELD_NAME_FILENAME,
		));
		array_push($proImageLevel,\haibao\cms\model\data\imagecollective\ImageCollectivePro::IMAGE_TYPE_ZERO);
		
		$imageCollProFilter->where(ImageCollProFilter::CONDITION_FIELD_NAME_IMAGE_IMAGE_TYPE,Condition::CONDITION_IN,$proImageLevel);
		$imageCollProFilter->where(ImageCollProFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_ID,Condition::CONDITION_IN,$collIdArr);
		$imageCollProFilter->leftJoin($imageLibraryFilter,null,ImageCollProFilter::CONDITION_FIELD_NAME_IMAGE_ID,ImageLibraryFitler::CONDITION_FIELD_NAME_ID,ImageCollProFilter::CONDITION_FIELD_NAME_IMAGE_FILENAME,false);
	
		$collProImages = $this->imageCollData->getAll($imageCollProFilter);
		
		$proImageArr = array();
		foreach($collProImages as $proImage){
			if(isset($proImageArr[$proImage->ImageCollectiveId])){
				$proImageArr[$proImage->ImageCollectiveId][$proImage->ImageType] = $proImage->FileName->Filename;
			}else{
				$proImageArr[$proImage->ImageCollectiveId] = array();
				$proImageArr[$proImage->ImageCollectiveId][$proImage->ImageType] = $proImage->FileName->Filename;
			}
		}
		return $proImageArr;
	}
	
	
	/**
	 * 取得最新的单品和品牌
	 */
	public function getNewProductAndBrand($limit = 8){
		$brandPic = array();
		$result = array();
		$productInfo = array();
		$productImage = array();
		$oldProduct = array();
		$imageBusniess = new \haibao\cms\business\ImageLibrary();
		$publicControllerData = new PublicControllerData();
		$param['limit'] = $limit;
		$productInfo = $publicControllerData->getNewProductAndBrand($param);
		$brandId = array();
		foreach($productInfo as $key => $value){
			$brandId[] = $value['BrandId'];
			$productPicId[] = $value['PicId'];
			$brandTagId[] = $value['BrandTagId'];
			$productId[] = $value['Id'];
		}
		
		$tagsById = \haibao\cms\business\Tag::getTagsById($brandTagId);
		$brandPic = $this->getBrandPicsById($brandId);
		$productImage = $imageBusniess::getImageUrlById($productPicId);		
		$oldProduct = $this->getOldData($productId,'ProductModel');		
		
		foreach($productInfo as $key => $value){
			$result[$key]['Name'] = $value['ProductName'];
			$result[$key]['BrandId'] = $value['BrandId'];
			$result[$key]['ProductId'] = $value['Id'];
			$result[$key]['CategoryId'] = $value['CategoryId'];
			$result[$key]['CategoryName'] = $value['CategoryName'];
			if(!empty($value['NameCN'])){
			    $result[$key]['BrandCNName'] = $value['NameCN'];
			}else{
			    $result[$key]['BrandCNName'] = '';
			}
			if(!empty($value['NameEN'])){
			    $result[$key]['BrandENName'] = $value['NameEN'];
			}else{
			    $result[$key]['BrandENName'] = '';
			}
			
			if($value['Id'] && array_key_exists($value['Id'], $oldProduct)){
				$result[$key]['oldProductId'] = $oldProduct[$value['Id']];
			}else{
				$result[$key]['oldProductId'] = "";
			}
			if($value['BrandTagId'] && array_key_exists($value['BrandTagId'],$tagsById)){
				$result[$key]['BrandUrl'] = $tagsById[$value['BrandTagId']]['Url'];
			}else{
				$result[$key]['BrandUrl'] = "";
			}		
			if($value['BrandId']>0 && array_key_exists($value['BrandId'], $brandPic)){
				$result[$key]['BrandPic'] = $brandPic[$value['BrandId']]['Filename'];
			}else{
				$result[$key]['BrandPic'] = "";
			}
			if($value['PicId']>0 && array_key_exists($value['PicId'], $productImage)){
				$result[$key]['ProductPic'] = $productImage[$value['PicId']];
			}else{
				$result[$key]['ProductPic'] = "";
			}
		}
		return $result;
	}
	
	/**
	 * 取得最新的单品和品牌
	 */
	public function getNewProductAndBrandList($limit = 8){
		$brandPic = array();
		$result = array();
		$productInfo = array();
		$productImage = array();
		$oldProduct = array();
		$imageBusniess = new \haibao\cms\business\ImageLibrary();
		$publicControllerData = new PublicControllerData();
		$param['limit'] = $limit;
		$productInfo = $publicControllerData->getNewProductAndBrandList($param);
		$brandId = array();
		foreach($productInfo as $key => $value){
			$brandId[] = $value['BrandId'];
			$productPicId[] = $value['PicId'];
			$brandTagId[] = $value['BrandTagId'];
			$productId[] = $value['Id'];
		}
	
		$tagsById = \haibao\cms\business\Tag::getTagsById($brandTagId);
		$brandPic = $this->getBrandPicsById($brandId);
		$productImage = $imageBusniess::getImageUrlById($productPicId);
		$oldProduct = $this->getOldData($productId,'ProductModel');
	
		foreach($productInfo as $key => $value){
			$result[$key]['Name'] = $value['ProductName'];
			$result[$key]['BrandId'] = $value['BrandId'];
			$result[$key]['ProductId'] = $value['Id'];
			$result[$key]['CategoryId'] = $value['CategoryId'];
			$result[$key]['CategoryName'] = $value['CategoryName'];
			$result[$key]['ParentId'] = $value['ParentId'];
			if(!empty($value['NameCN'])){
				$result[$key]['BrandCNName'] = $value['NameCN'];
			}else{
				$result[$key]['BrandCNName'] = '';
			}
			if(!empty($value['NameEN'])){
				$result[$key]['BrandENName'] = $value['NameEN'];
			}else{
				$result[$key]['BrandENName'] = '';
			}
				
			if($value['Id'] && array_key_exists($value['Id'], $oldProduct)){
				$result[$key]['oldProductId'] = $oldProduct[$value['Id']];
			}else{
				$result[$key]['oldProductId'] = "";
			}
			if($value['BrandTagId'] && array_key_exists($value['BrandTagId'],$tagsById)){
				$result[$key]['BrandUrl'] = $tagsById[$value['BrandTagId']]['Url'];
			}else{
				$result[$key]['BrandUrl'] = "";
			}
			if($value['BrandId']>0 && array_key_exists($value['BrandId'], $brandPic)){
				$result[$key]['BrandPic'] = $brandPic[$value['BrandId']]['Filename'];
			}else{
				$result[$key]['BrandPic'] = "";
			}
			if($value['PicId']>0 && array_key_exists($value['PicId'], $productImage)){
				$result[$key]['ProductPic'] = $productImage[$value['PicId']];
			}else{
				$result[$key]['ProductPic'] = "";
			}
		}
		return $result;
	}
	
	public function getOldData($primarykeyArray,$tableName){
		if(empty($primarykeyArray) || empty($tableName)){
			return array();
		}
		$data = array();
		$dataMigrationMapFilter = new DataMigrationMapFilter();
		$dataMigrationMapFilter->select(array(
				DataMigrationMapFilter::CONDITION_FIELD_NAME_OLDPRIMARYKEY,
				DataMigrationMapFilter::CONDITION_FIELD_NAME_PRIMARYKEY,
				DataMigrationMapFilter::CONDITION_FIELD_NAME_TABLENAME
		));
		$dataMigrationMapFilter->where(DataMigrationMapFilter::CONDITION_FIELD_NAME_PRIMARYKEY,Condition::CONDITION_IN, $primarykeyArray);
		$dataMigrationMapFilter->where(DataMigrationMapFilter::CONDITION_FIELD_NAME_TABLENAME,Condition::CONDITION_EQUAL, $tableName);
		$dataMigrationMapData = new \haibao\cms\data\DataMigrationMap();
		$result = $dataMigrationMapData->getAll($dataMigrationMapFilter);
		foreach($result as $key => $value){
			$data[$value->PrimaryKey] = $value->OldPrimaryKey;
		}		
		return $data;
	}
	
	
	/**
	 * 得到品牌的小图（品牌的logo图）
	 * @param array $brandId
	 */
	public function getBrandPicsById($brandId){
		if(empty($brandId)) return array();
		$brandData = new \haibao\cms\data\Brand();
		$data = array();
		$result= array();
		$brandFilter = new \haibao\cms\model\filter\Brand;
		$imageFilter = new ImageLibraryFitler;
		$brandFilter->select(array(
				\haibao\cms\model\filter\Brand::CONDITION_FIELD_NAME_ID,
				\haibao\cms\model\filter\Brand::CONDITION_FIELD_NAME_IMGID,
				\haibao\cms\model\filter\Brand::CONDITION_FIELD_NAME_NAMECN,
				\haibao\cms\model\filter\Brand::CONDITION_FIELD_NAME_NAMEEN
	
		));
		$imageFilter->select(array(
				ImageLibraryFitler::CONDITION_FIELD_NAME_ID,
				ImageLibraryFitler::CONDITION_FIELD_NAME_FILENAME
	
		));
		$brandFilter->leftJoin($imageFilter,null,\haibao\cms\model\filter\Brand::CONDITION_FIELD_NAME_IMGID,ImageLibraryFitler::CONDITION_FIELD_NAME_ID,\haibao\cms\model\filter\Brand::CONDITION_FIELD_NAME_BRAND_PIC,false);
		$brandFilter->where(\haibao\cms\model\filter\Brand::CONDITION_FIELD_NAME_ID, Condition::CONDITION_IN, $brandId);
	
		$data = $brandData->getAll($brandFilter);
	
		foreach($data as $key => $val){
			$result[$val->Id]['Filename']= $val->BrandPic->Filename;
		}
		return $result;
	}
	
	/**
	 * 得到明星示范
	 */
	public function getStarExample(){ //原尚库  明星示范  用到
		$publicControllerData = new PublicControllerData();
		$tagBusiness = new TagBusiness();
		$articleArray=array();
		$starInfo = array();
		$brandInfo = array();
		$data = array();
		$ArticleTopTagId = array();
		$param['limit'] = 4;
		$articleArray = $publicControllerData->getStarExample($param);
		foreach($articleArray as $key => $value){
			$articleId[] = $value['Id'];
		}
		$this->articleIdArr = $articleId;
		$ArticleTopTagId = $this->getArticleTagByArticleId();	
		$articleProImg = $this->getArticleProImage($articleId,6);
		$starInfo = $publicControllerData->getStarByArticle($articleId);		
		$brandInfo = $publicControllerData->getBrandByArticle($articleId);		
		foreach($articleArray as $key => $value){
			$data[$key]['ArticleId'] =  $value['Id'];
			$data[$key]['PublishId'] = $value['PublishId'];
			$data[$key]['StarImage'] =  $starInfo[$value['Id']]['Filename'];
			$data[$key]['BrandImage'] =  $brandInfo[$value['Id']]['Filename'];
			$data[$key]['StarTagId'] =  $starInfo[$value['Id']]['TagId'];
			$data[$key]['BrandTagId'] =  $brandInfo[$value['Id']]['TagId'];
			if(isset($articleProImg[$value['Id']][6])){
				$data[$key]['ArticlProImage'] = $articleProImg[$value['Id']][6];
			}else{
				if(isset($articleProImg[$value['Id']][0])){
				$data[$key]['ArticlProImage'] = $articleProImg[$value['Id']][0];
				}else{
					$data[$key]['ArticlProImage'] = '';
				}
			}
			
			$data[$key]['Title'] = $value['Title'];
			//$data[$key]['ClickNum'] = $value['ClickNum'];
			//$data[$key]['CommentNum'] = $value['CommentNum'];
			$data[$key]['PublishTime'] = $value['PublishTime'];
			$data[$key]['StarNameEn'] = $starInfo[$value['Id']]['NameEn'];
			$data[$key]['StarNameCn'] = $starInfo[$value['Id']]['NameCn'];
			$data[$key]['StarFansCount'] = $starInfo[$value['Id']]['FansCount'];
			$data[$key]['BrandFansCount'] = $brandInfo[$value['Id']]['FansCount'];
			$data[$key]['BrandNameEn'] = $brandInfo[$value['Id']]['NameEn'];
			$data[$key]['BrandNameCn'] = $brandInfo[$value['Id']]['NameCn'];
			$data[$key]['TopTagId'] = $ArticleTopTagId[$value['Id']];
			$data[$key]['StarTopicId'] = TagBusiness::getTopicIdByTagId($starInfo[$value['Id']]['TagId']);
			$data[$key]['BrandTopicId'] = TagBusiness::getTopicIdByTagId($brandInfo[$value['Id']]['TagId']);
			$data[$key]['StarId'] =  $starInfo[$value['Id']]['StarId'];
			$data[$key]['BrandId'] = $brandInfo[$value['Id']]['BrandId'];
		}	

		return $data;
	}
	
	
	
	public function initParam(){

		$this->imageColls = array();
		$this->articles = array();
		$this->articleIdArr = array();
		$this->collIdArr = array();
		$this->tagIdArr = array();
		$this->collTagIdArr = array();
		$this->articleProImages = array();
		$this->collProImages = array();
		$this->tagInfo = array();
		$this->collTagInfo= array();
		$this->isDate = false;
		$this->isImageColl = true;
		$this->isParentTag = true;
		
		$this->articleTagArr = array();
		$this->collTagArr = array();
		
		$this->hasParentId = false;
		$this->orderByNew = true;
		
		$this->bigLevel = 0;
		$this->offset = 0;
		$this->primaryTag = 0;
		/* $this->isArticleTag = false;
		$this->isConditionTag = true;
		$this->isPrimaryTag = false;
		$this->isReturnTag = false;
		$this->isProImage = false;
		$this->proImageLevel = array(); */
	}
	
	private function packageQueryTypeChannelReturnData(){

		$article = array(
				'list'=>$this->articles,
				'proImage'=>$this->articleProImages,
				'tag'=>$this->tagInfo,
				'articleTag'=>$this->articleTagArr
				
		);
		$imageColl = array(
				'list'=>$this->imageColls,
				'proImage'=>$this->collProImages,
				'tag'=>$this->collTagInfo,
				'collTag'=>$this->collTagArr
		);
		return array($article,$imageColl);
	}
	

	/**
	 * set get 方法
	 */
	public function setLimit($limit){
		$this->limit = $limit;
	}
	public function getLimit(){
		return $this->limit;
	}
	
	public function setLevel($level){
		$this->level = $level;
	}
	public function getLevel(){
		return $this->level;
	}
	public function setBigLevel($bigLevel){
		$this->bigLevel = $bigLevel;
	}
	
	public function getBigLevel(){
		return $this->bigLevel;
	}
	
	public function setIsArticleTag($isArticleTag,$tagIds = '',$isPrimaryTag = false,$isReturnTag=false,$isParentTag = true,$isConditionTag = true,$isReturnPrimary = true){
		if($isArticleTag){
			$this->tagIds = $tagIds;
			$this->isPrimaryTag = $isPrimaryTag;
			$this->isReturnTag = $isReturnTag;
			$this->isParentTag = $isParentTag;
			$this->isConditionTag = $isConditionTag;
			$this->isReturnPrimary = $isReturnPrimary;
		}
		$this->isArticleTag = $isArticleTag;
		
	}
	public function getIsArticleTag(){
		return $this->isArticleTag;
	}
	private function getTagIds(){
		return $this->tagIds;
	}
	private function getTagUrls(){
		return $this->tagUrls;
	}
	private function getIsReturnTag(){
		return $this->isReturnTag;
	}
	private function getIsConditionTag(){
		return $this->isConditionTag;
	}
	public function setIsProImage($isProImage,$proImageLevel = array()){
		if($isProImage) $this->proImageLevel = $proImageLevel;
		$this->isProImage = $isProImage;
	}
	public function getIsProImage(){
		return $this->isProImage;
	}
	private function getProImageLevel(){
		return $this->proImageLevel;
	}
	public function setRelType($relType){
		$this->relType = $relType;
	}
	public function getRelType(){
		return $this->relType;
	}
	public function setSource($source){
		$this->source = $source;
	}
	public function getSource(){
		return $this->source;
	}
	public function setIsDate($isDate,$dateType){
		if($isDate){
			$this->dateType = $dateType;
		}
		$this->isDate = $isDate;
	}
	public function getIsDate(){
		return $this->isDate;
	}
	public function setIsPage($isPage){
		$this->isPage = $isPage;
	}
	public function getIsPage(){
		return $this->isPage;
	}
	public function setIsImageColl($isImageColl){
		$this->isImageColl = $isImageColl;
	}
	public function getIsImageColl(){
		return $this->isImageColl;
	}
	public function setCurrentPage($currentPage){
		$this->currentPage = $currentPage;
	}
	public function getCurrentPage(){
		return $this->currentPage;
	}
	
	public function setHasParentId($hasParentId){
		$this->hasParentId = $hasParentId;
	}
	public function getHasParentId(){
		return $this->hasParentId;
	}	
	
	public function setOrderByNew($orderByNew){
		$this->orderByNew = $orderByNew;
	}
	public function getOrderByNew(){
		return $this->orderByNew;
	}
	
	public function setIsParentTag($isParentTag){
		$this->isParentTag = $isParentTag;
	}
	public function getIsParentTag(){
		return $this->isParentTag;
	}
	
	public function setOffset($offset){
		$this->offset = $offset;
	}
	public function getOffset(){
		return $this->offset;
	}
	public function setPrimaryTag($primaryTag){
		$this->primaryTag = $primaryTag;
	}

	public function setIsCalendarData($isCalendarData){
		$this->isCalendarData = $isCalendarData;
	}
	
	
	/**
	 * 查询包含当前频道标签的最新资讯信息 频道页今日最新使用
	 *@param : Int $queryType
	 */
	public function getChannelArticleMustInTopTagId(){
		
		$this->getArticleMustInTopTagId();
		if($this->getIsImageColl()){
			$this->getImageCollMustInTopTagId();
			list($first,$second) = $this->packageQueryTypeChannelReturnData();
			return array($first,$second);
		}else{
		return array($this->articles,$this->articleProImages,$this->tagInfo,$this->articleTagArr);
		}
		
	
	}
    
	/**
	 * 
	 */
	private function getArticleMustInTopTagId(){
		$articleFilter = new ArticleFilter();
		$articleFilter->select(
				array(
						ArticleFilter::CONDITION_FIELD_NAME_ID,
						ArticleFilter::CONDITION_FIELD_NAME_TITLE,
						ArticleFilter::CONDITION_FIELD_NAME_SHORTTITLE,
						ArticleFilter::CONDITION_FIELD_NAME_PUBLISHTIME,
						ArticleFilter::CONDITION_FIELD_NAME_ARTICLE_PUBLISHID
				)
		);
		$articleFilter->order(ArticleFilter::CONDITION_FIELD_NAME_PUBLISHTIME,false);
		$articleFilter->limit(0,$this->getLimit());
		if($this->getLevel() == -2){
			$articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_LESSEQUAL,2);
		}else{
			$bigLevel = $this->getBigLevel();
			$level = $this->getLevel();
			if(!empty($bigLevel)){
				if($bigLevel != $level){
					$articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_GREATEREQUAL,$level);
					$articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_LESSEQUAL,$bigLevel);
				}else {
					$articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_EQUAL,$level);
				}
			}else {
				$articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_GREATEREQUAL,$level);
			}
		
		}
		
		$articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_PUBLISHED,Condition::CONDITION_EQUAL,\haibao\cms\model\data\Article::PUBLISHED_YES);
		$articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_STATUS,Condition::CONDITION_EQUAL,\haibao\cms\model\data\Article::STATUS_ENABLE);
		
		if($this->getIsArticleTag()){
			$articleTagFilter = new ArticleTagFilter();
			$articleTagFilter->select(
					array(
							ArticleTagFilter::CONDITION_FIELD_NAME_ARTICLE_ID,
							ArticleTagFilter::CONDITION_FIELD_NAME_TAG_ID,
							ArticleTagFilter::CONDITION_FIELD_NAME_PARENT_ID,
							ArticleTagFilter::CONDITION_FIELD_NAME_IS_PRIMAIY,
					)
			);
			if($this->getIsConditionTag()){
				if(is_array($this->getTagIds())){
					if(!$this->isParentTag){
						$articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_TAG_ID,Condition::CONDITION_IN,$this->getTagIds());
					}
				}else{
					if(!$this->isParentTag){
						$tagId = (int)$this->getTagIds();
						$articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_TAG_ID,Condition::CONDITION_EQUAL,$tagId);
					}
				}
				if($this->isPrimaryTag){
					$articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_IS_PRIMAIY,Condition::CONDITION_EQUAL,\haibao\cms\model\data\ArticleTag::PRIMAIY_IS);
				}
			}else{
				if($this->isPrimaryTag){
					$articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_IS_PRIMAIY,Condition::CONDITION_EQUAL,\haibao\cms\model\data\ArticleTag::PRIMAIY_IS);
				}
			}
			if($this->hasParentId){
				$articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_TAG_ID,Condition::CONDITION_IN,(array)$this->tagIds);
			}
			$articleFilter->leftJoin($articleTagFilter,null,ArticleFilter::CONDITION_FIELD_NAME_ID,ArticleTagFilter::CONDITION_FIELD_NAME_ARTICLE_ID,ArticleFilter::CONDITION_FIELD_NAME_ARTICLE_TAG,false);
		}
		
		$articles = $this->articleData->getAll($articleFilter);
		$count = count($articles);
		foreach($articles as $key=>$article){
			$article->SiteType = self::INFO_TYPE_ARTICLE;
			$publishTime = strtotime($article->PublishTime->format('Y-m-d H:i:s')) + $count - $key;
			$this->articles[$publishTime] = $article;
			array_push($this->articleIdArr,$article->Id);
		}
		if($this->getIsProImage()){
			if($this->articleIdArr){
				$this->articleProImages = $this->getArticleProImage($this->articleIdArr,$this->getProImageLevel());
			}
		}
		if($this->getIsReturnTag()){
			if($this->isParentTag){
				if($this->articleIdArr){
					$this->articleTagArr = $this->getArticleTagByArticleId();
					$tmpTagIds = array();
					foreach($this->articleTagArr as $arr){
						array_push($tmpTagIds,$arr['TagId']);
					}
					$this->tagInfo = PublicControllerBusiness::getTagInfoById(array_unique($tmpTagIds),$this->getSource());
				}
			}
		}
	}
	
	public function getImageCollMustInTopTagId($isRemoveArticle = false){
	$imageCollFilter = new ImageCollFilter();
		$imageCollFilter->select(
				array(
						ImageCollFilter::CONDITION_FIELD_NAME_ID,
						ImageCollFilter::CONDITION_FIELD_NAME_TITLE,
						ImageCollFilter::CONDITION_FIELD_NAME_SHORT_TITLE,
						ImageCollFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_PUBLISHTIME,
				)
		);
		$imageCollFilter->order(ImageCollFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_PUBLISHTIME,false);
		$imageCollFilter->limit(0,$this->getLimit());
		$bigLevel = $this->getBigLevel();
		$level = $this->getLevel();
		if(!empty($bigLevel)){
			if($bigLevel != $level){
				$imageCollFilter->where(ImageCollFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_GREATEREQUAL,$level);
				$imageCollFilter->where(ImageCollFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_LESSEQUAL,$bigLevel);
			}else {
				$imageCollFilter->where(ImageCollFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_EQUAL,$level);
			}
		}else {
			$imageCollFilter->where(ImageCollFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_GREATEREQUAL,$level);
		}
		
		$imageCollFilter->where(ImageCollFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_PUBLISHED,Condition::CONDITION_EQUAL,\haibao\cms\model\data\imagecollective\ImageCollective::STATUS_YES_PUBLISH);
		
		if($isRemoveArticle){
			if($this->articleIdArr){
				$imageCollArticleFilter = new ImageCollArticleFilter();
				if(is_array($this->articleIdArr)){
					$imageCollArticleFilter->where(ImageCollArticleFilter::CONDITION_FIELD_NAME_ARITCLE_ID, Condition::CONDITION_OR,array(
							new Condition(ImageCollArticleFilter::CONDITION_FIELD_NAME_ARITCLE_ID, Condition::CONDITION_NOTIN, $this->articleIdArr),
							new Condition(ImageCollArticleFilter::CONDITION_FIELD_NAME_ARITCLE_ID, Condition::CONDITION_IS_NULL, null),
					));
				}else{
					$imageCollArticleFilter->where(ImageCollArticleFilter::CONDITION_FIELD_NAME_ARITCLE_ID, Condition::CONDITION_OR,array(
							new Condition(ImageCollArticleFilter::CONDITION_FIELD_NAME_ARITCLE_ID, Condition::CONDITION_NOTEQUAL, $this->articleIdArr),
							new Condition(ImageCollArticleFilter::CONDITION_FIELD_NAME_ARITCLE_ID, Condition::CONDITION_IS_NULL, null),
					));
				}
				$imageCollFilter->leftjoin($imageCollArticleFilter,null,ImageCollFilter::CONDITION_FIELD_NAME_ID,ImageCollArticleFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_ID);
			}
		}
		
		if($this->getIsArticleTag()){
			$imageCollTagFilter = new ImageCollTagFilter();
			$imageCollTagFilter->select(
					array(
							ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_COLLECTIVE_ID,
							ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ID,
							ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_PARENTID,
							ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ISPRIMAIY,
					)
			);
			
			if($this->getIsConditionTag()){
				if(is_array($this->getTagIds())){
					if(!$this->isParentTag){
						$imageCollTagFilter->where(ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ID,Condition::CONDITION_IN,$this->getTagIds());
					}
				}else{
					if(!$this->isParentTag){
						$tagId = (int)$this->getTagIds();
						$imageCollTagFilter->where(ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ID,Condition::CONDITION_EQUAL,$tagId);
					}
				}
				if($this->isPrimaryTag){
					$imageCollTagFilter->where(ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ISPRIMAIY,Condition::CONDITION_EQUAL,\haibao\cms\model\data\imagecollective\ImageCollectiveTag::IS_PRIMAIY);
				}
			}else{
				if($this->isPrimaryTag){
					$imageCollTagFilter->where(ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ISPRIMAIY,Condition::CONDITION_EQUAL,\haibao\cms\model\data\imagecollective\ImageCollectiveTag::IS_PRIMAIY);
				}
			}
			if($this->hasParentId){
				$imageCollTagFilter->where(ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_ID,Condition::CONDITION_IN,(array)$this->tagIds);
			}
			$imageCollFilter->leftJoin($imageCollTagFilter,null,ImageCollFilter::CONDITION_FIELD_NAME_ID,ImageCollTagFilter::CONDITION_FIELD_NAME_TAG_COLLECTIVE_ID,ImageCollFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_TAG,false);
		}
		
		$imageColls = $this->imageCollData->getAll($imageCollFilter);
		$count = count($imageColls);
		foreach($imageColls as $key=>$imageColl){
			$imageColl->SiteType = self::INFO_TYPE_IMAGE;
			$time = strtotime($imageColl->PublishTime->format('Y-m-d H:i:s')) + $count - $key;
			$this->imageColls[$time] = $imageColl;
			array_push($this->collIdArr,$imageColl->Id);
			
		}
		if($this->getIsProImage()){
			if($this->collIdArr){
				$this->collProImages = $this->getCollProImage($this->collIdArr,$this->getProImageLevel());
			}
		}
		if($this->getIsReturnTag()){
			
			if($this->isParentTag){
				
				if($this->collIdArr){
					$this->collTagArr = $this->getCollTagByCollId(array(),$this->isReturnPrimary);
					$tmpTagIds = array();
					foreach($this->collTagArr as $arr){
						array_push($tmpTagIds,$arr['TagId']);
					}
					$this->collTagInfo = PublicControllerBusiness::getTagInfoById(array_unique($tmpTagIds),$this->getSource());
				}
			}
		}
	}
	
	/**
	 * WAP站获取资讯列表
	 */
	public function getWapInfoList($channelType){		
		$level = 4;
		if($channelType){
			$level = 3;
		}
		
		$wapInfoFilter = new WapInfoFilter();
		$wapInfoFilter->select(array(
				WapInfoFilter::CONDITION_FIELD_NAME_INFO_ID,
				WapInfoFilter::CONDITION_FIELD_NAME_TITLE,
				WapInfoFilter::CONDITION_FIELD_NAME_INFO_TYPE,
				WapInfoFilter::CONDITION_FIELD_NAME_TAG_ID,
				WapInfoFilter::CONDITION_FIELD_NAME_PUBLISH_ID,
	    		WapInfoFilter::CONDITION_FIELD_NAME_PUBLISH_TIME,
		));
		
		$wapInfoFilter->where(WapInfoFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_GREATEREQUAL,$level);
		
		if($this->getIsArticleTag()){
			if(is_array($this->getTagIds())){
				$wapInfoFilter->where(WapInfoFilter::CONDITION_FIELD_NAME_TAG_ID,Condition::CONDITION_IN, $this->getTagIds());
			}else{
				$wapInfoFilter->where(WapInfoFilter::CONDITION_FIELD_NAME_TAG_ID,Condition::CONDITION_EQUAL, (int)$this->getTagIds());
			}
			//$wapInfoFilter->order(WapInfoFilter::CONDITION_FIELD_NAME_CHANNEL_TOP,false);
		}else{

			//$wapInfoFilter->order(WapInfoFilter::CONDITION_FIELD_NAME_INDEX_TOP,false);
		}

		$wapInfoFilter->where(WapInfoFilter::CONDITION_FIELD_NAME_PUBLISH_TIME,Condition::CONDITION_LESSEQUAL,date('Y-m-d H:i:s',time()));
		$wapInfoFilter->order(WapInfoFilter::CONDITION_FIELD_NAME_PUBLISH_TIME,false);
		$wapInfoFilter->limit(($this->getCurrentPage()-1)*$this->getLimit(),$this->getLimit());
		$this->pager = $wapInfoFilter->getPager();
		$this->articles = $this->articleData->getAll($wapInfoFilter);
		
		$articleInfoArr = $imageCollInfoArr = array();
		
		if($this->articles){
			
			foreach($this->articles as $info){
				if($info->InfoType == \haibao\cms\model\data\WapInfo::INFO_TYPE_ARTICLE){
					array_push($this->articleIdArr,$info->InfoId);
				}elseif($info->InfoType == \haibao\cms\model\data\WapInfo::INFO_TYPE_IMAGE_COLLECTIVE){
					array_push($this->collIdArr,$info->InfoId);
				}else{
					
				}
				array_push($this->allArticleId,$info->InfoId);
			}
			if($this->getIsProImage()){
			
				if($this->articleIdArr){
					$this->articleProImages = $this->getArticleProImage($this->articleIdArr,$this->getProImageLevel());
					$this->articleTagArr = $this->getArticleTagByArticleId();

					$articleFilter = new ArticleFilter();
					$articleFilter->select(
							array(
									ArticleFilter::CONDITION_FIELD_NAME_ID,
									ArticleFilter::CONDITION_FIELD_NAME_SHORTTITLE
							)
					);
					$articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_ID,Condition::CONDITION_IN,$this->articleIdArr);
					$articleInfoArr  = $this->articleData->getAll($articleFilter);
				}
				if($this->collIdArr){
					$this->collProImages = $this->getCollProImage($this->collIdArr, $this->getProImageLevel());
					$this->collTagArr = $this->getCollTagByCollId();
					
					$imageCollFilter = new ImageCollFilter();
					$imageCollFilter->select(
							array(
									ImageCollFilter::CONDITION_FIELD_NAME_ID,
									ImageCollFilter::CONDITION_FIELD_NAME_SHORT_TITLE,
							)
					);
					$imageCollFilter->where(ImageCollFilter::CONDITION_FIELD_NAME_ID,Condition::CONDITION_IN,$this->collIdArr);
					$imageCollInfoArr  = $this->articleData->getAll($imageCollFilter);
				}
			}
			
			if($channelType && $channelType == 'tv'){
			    $this->getArticleInTags = \haibao\cms\business\ArticleTag::getTagsByArticleIds($this->allArticleId,false,array(11310,11311,11312));
			}
		}
		/* else{
			throw new BusinessException('资讯为空(不是BUG测试用)',self::DATA_EMPTY);
		} */
		return array($this->articles,$articleInfoArr,$this->articleProImages,$imageCollInfoArr,$this->collProImages,$this->articleTagArr,$this->collTagArr,$this->getArticleInTags);
	}
}
